<template>
    <div>
        <Table ref="table" :loading="loading" stripe :columns="columns1" :data="data1"></Table>
        <Page :total="total" :current="search.page" show-sizer show-total :page-size="search.rows" @on-page-size-change="get_list_by_rows" @on-change="get_list_by_page"> </Page>

    </div>
</template>

<script>
    import {
        mapMutations,
        mapGetters
    } from 'vuex'
    import axios from '@/libs/api.request'
    export default {
        data() {
            return {
                // 加载状态
                loading: false,

                // 搜索对象
                search: {
                    page: 1,
                    rows: 10
                },

                // 数据总条数
                total: 0,

                columns1: [{
                        title: '角色名称',
                        align: 'left',
                        key: 'name'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 350,
                        align: 'center',
                        render: (h, params) => {
                            if (this.role < 3) {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'default',
                                            icon: 'md-brush',
                                        },
                                        style: {
                                            marginRight: '14px',
                                            height: '30px'
                                        },
                                        on: {
                                            click: () => {
                                                this.myClose('wx_app_power')
                                                this.$_changePage('wx_app_power', '小程序权限', {
                                                    id: params.row.id,
                                                    name: params.row.name
                                                })
                                            }
                                        }
                                    }, '小程序权限'),
                                    // h('Button', {
                                    //     props: {
                                    //         type: 'warning',
                                    //         size: 'default',
                                    //         icon: 'md-brush',
                                    //     },
                                    //     style: {
                                    //         marginRight: '14px',
                                    //         height: '30px'
                                    //     },
                                    //     on: {
                                    //         click: () => {
                                    //             this.myClose('console_power')
                                    //             this.$_changePage('console_power', '控制台权限', {
                                    //                 id: params.row.id
                                    //             })
                                    //         }
                                    //     }
                                    // }, '控制台权限'),
                                ])
                            }
                        }
                    }

                ],
                data1: []
            }
        },
        methods: {
            ...mapMutations(['myClose']),
            ...mapGetters(['getRole']),

            // 获取角色列表
            get_role_list() {
                this.loading = true
                let {
                    ...data
                } = this.search
                axios.ajax_post('admin-role-ajax_get_role', data).then(res => {
                    this.loading = false
                    if (res.data.code === 1) {
                        this.data1 = res.data.data.list
                        this.total = res.data.data.total_num
                    } else {
                        this.$Notice.error({
                            title: res.data.msg,
                            duration: 3
                        })
                    }
                })

            },

            get_list_by_rows(rows) {
                this.search.rows = rows
                this.get_role_list()
            },

            get_list_by_page(page) {
                this.search.page = page
                this.get_role_list()
            },

        },
        computed: {
            role() {
                return this.getRole()
            }
        },
        created() {
            this.get_role_list()
        },
    }
</script>

<style lang="less" scoped>

</style>